package com.wenfs.demo.service.impl;

import com.wenfs.demo.dao.SysMenuMapper;
import com.wenfs.demo.entity.SysMenu;
import com.wenfs.demo.service.ISysMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * @author wenfs
 */
@Service
public class SysMenuBo implements ISysMenu {
  @Autowired
  private SysMenuMapper sysMenuMapper;

  @Override
  public Set<String> getMenuCodesByUserCode(String userCode) {
    return sysMenuMapper.getMenuCodesByUserCode(userCode);
  }

  @Override
  public List<SysMenu> findAll() {
    return sysMenuMapper.findAll();
  }

  @Override
  public int save(SysMenu menu) {
    menu.setMenuId(UUID.randomUUID().toString());
    Integer maxCode = sysMenuMapper.getMaxCode();
    menu.setMenuCode(String.valueOf(maxCode + 1));
    menu.setCreateTime(String.valueOf(System.currentTimeMillis()));
    menu.setUpdateTime(String.valueOf(System.currentTimeMillis()));
    menu.setMenuStatus((byte) 1);
    return sysMenuMapper.save(menu);
  }

  @Override
  public void setStatus(Integer status, String menuCode) {
    sysMenuMapper.setStatus(status,menuCode);
  }
}
